#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define y1 y_alpha_1

using namespace std;

using ll = long long;
using db = double;
using vec = vector<int>;
using pii = pair<int,int>;

int read() {
	int x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-',ch = getchar();
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48),ch = getchar();
	return f ? -x : x;
}

const int N = 1e5 + 10;
const int mod = 1e9 + 7;

int dis[N << 4],nodenum,n,m;
bool vis[N << 4];
vec G[N << 4][12];

void link(int x,int y,int w) {
	while(w >= 10) {
		++nodenum; G[nodenum][w % 10].pb(y); y = nodenum; w /= 10;
	}
	G[x][w].pb(y);
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in;m = in; nodenum = n;
	for(int i = 1,u,v;i <= m;i++) u = in,v = in,link(u,v,i),link(v,u,i);
	vec t; t.pb(1); queue < vec > q; q.push(t); vis[1] = 1;
	while(!q.empty()) {
		vec d = q.front(); q.pop();
		for(int i = 0;i <= 9;i++) {
			vec tmp; t.swap(tmp);
			for(auto x : d) {
				for(auto y : G[x][i]) 
					if(!vis[y]) vis[y] = 1,dis[y] = (dis[x] * 10ll % mod + i) % mod,t.pb(y);
			}
			if(t.size()) q.push(t);
		}
	}
	for(int i = 2;i <= n;i++) printf("%d\n",dis[i]);
	return 0;
}
